var _n59;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$EventManager = require("EventManager");
var s = cc__importDefault($1$EventManager);
var $GameEventType = require("GameEventType");
var $1$TimePlugIn = require("TimePlugIn");
var l = cc__importDefault($1$TimePlugIn);
var $1$gameConfig1 = require("gameConfig1");
var u = cc__importDefault($1$gameConfig1);
var $1$userService = require("userService");
var p = cc__importDefault($1$userService);
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var $1$zqcc_pageBase = require("zqcc_pageBase");
var h = cc__importDefault($1$zqcc_pageBase);
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_getPowerPage = function (t) {
  function _ctor() {
    // 调用 t 函数，如果返回 null，则使用 this
    const e = null !== t && t.apply(this, arguments) || this;

    // 设置对象的初始属性
    e.pageName = "获取体力";
    e.lbRePowerCnt = null;
    e.number = null;
    e.changwanBtn = null;
    e.tips = null;
    e.tips2 = null;
    e.wuxiandaojishi = null;
    e.tilitubiaoNode = null;

    // 返回初始化后的对象
    return e;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.onLoad = function () { };
  _ctor.prototype.start = function () {
    this.node.zIndex = 9999;
    this.updateVideoCnt();
    this._init();
  };
  _ctor.prototype._init = function () {
    this.open();
  };
  _ctor.prototype.OnBtnConfirm = function () {
    // 播放按钮音效
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();

    // 检查用户的体力
    if ($zqcc_OverallSystem.sers().userSrv.power >= u.default.MAX_POWER) {
      $zqcc_OverallSystem.sers().uiSrv.showMessage("体力已满");
    } else {
      // 加载和显示视频广告
      $zqcc_OverallSystem.sers().platformSrv.platformApi.loadAndShowVideoAd(
        function () {
          // 广告播放完成后增加体力
          $zqcc_OverallSystem.sers().userSrv.addPower(u.default.VIDEO_GET_POWER);
          $zqcc_OverallSystem.sers().uiSrv.showMessage("获得体力" + u.default.VIDEO_GET_POWER + "点");
        },
        function () { }, // 广告失败回调函数
        null,
        {
          scene: "获得体力",
          event: "获得体力"
        },
        "common_video" // 广告类型
      );
    }
  };
  _ctor.prototype.jinbigoumai = function () {
    // 播放按钮音效
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();

    // 检查用户体力和金币
    const userService = $zqcc_OverallSystem.sers().userSrv;

    if (userService.power >= u.default.MAX_POWER) {
      $zqcc_OverallSystem.sers().uiSrv.showMessage("体力已满");
    } else if (userService.coin < 200) {
      $zqcc_OverallSystem.sers().uiSrv.showMessage("金币不足");
    } else {
      // 扣除金币并增加体力
      userService.addCoin(-200);
      userService.addPower(u.default.VIDEO_GET_POWER);
      $zqcc_OverallSystem.sers().uiSrv.showMessage("获得体力" + u.default.VIDEO_GET_POWER + "点");

      // 发送金币更新事件
      s.default.emit($GameEventType.EventType.DirectorEvent.updataGold);
    }
  };
  _ctor.prototype.OnBtnEnterInifinityMod = function () {
    const t = this; // 保留对当前上下文的引用

    // 播放按钮音效
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();

    // 检查是否启用了“畅玩模式”
    const infinityPowerModel = Number($zqcc_OverallSystem.sers().localStorageSrv.get(p.default.infinityPowerModel));
    if (infinityPowerModel !== 0) {
      $zqcc_OverallSystem.sers().uiSrv.showMessage("已经开启畅玩模式！");
      this.changwanBtn.active = false; // 隐藏按钮
    } else {
      // 加载和显示视频广告
      $zqcc_OverallSystem.sers().platformSrv.platformApi.loadAndShowVideoAd(
        function () {
          window.LookCnt = (window.LookCnt || 0) + 1; // 初始化并增加观看计数
          if (window.LookCnt >= 3) {
            // 达到观看次数，增加体力
            $zqcc_OverallSystem.sers().userSrv.addPower(1999);
            $zqcc_OverallSystem.sers().localStorageSrv.set(p.default.infinityPowerModel, 1);
            $zqcc_OverallSystem.sers().localStorageSrv.set(p.default.infinityPowerDate, Date.now());
            $zqcc_OverallSystem.sers().localStorageSrv.set(p.default.changwanModel, 1);
            $zqcc_OverallSystem.sers().localStorageSrv.set(p.default.changwanModelDate, Date.now());
            s.default.emit($GameEventType.EventType.UIEvent.updataGamelist); // 更新游戏列表
          }
          t.updateVideoCnt(); // 更新视频计数
        },
        function () { }, // 广告失败回调
        null,
        {
          scene: "24小时无限体力畅玩",
          event: "24小时无限体力畅玩"
        },
        "common_video" // 广告类型
      );
    }
  };
  _ctor.prototype.updateVideoCnt = function () {
    // 更新提示文本
    this.tips.string = `（${window.LookCnt}/3）`;

    // 检查是否启用了“畅玩模式”，并更新按钮状态
    const isInfinityPowerEnabled = Number($zqcc_OverallSystem.sers().localStorageSrv.get(p.default.infinityPowerModel)) !== 1;
    this.changwanBtn.active = isInfinityPowerEnabled;

    // 根据按钮状态更新提示和其他节点的可见性
    this.tips2.node.active = this.changwanBtn.active;
    this.wuxiandaojishi.node.active = !this.changwanBtn.active;
  };
  _ctor.prototype.OnBtnClose = function () {
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    this.onlyClose();
  };
  _ctor.prototype.update = function () {
    const powerModel = Number($zqcc_OverallSystem.sers().localStorageSrv.get(p.default.infinityPowerModel));

    // 如果无限力量模型不为0
    if (powerModel !== 0) {
      this.tilitubiaoNode.children[1].active = false;
      this.tilitubiaoNode.children[2].active = false;
      this.tilitubiaoNode.children[3].active = true;

      const currentTime = Date.now();
      const storedTime = Number($zqcc_OverallSystem.sers().localStorageSrv.get(p.default.infinityPowerDate));
      const isPowerModelValid = powerModel !== 0;
      const isTimeExceeded = (currentTime - storedTime) >= 864e5; // 86400000ms = 1天

      this.wuxiandaojishi.string = `剩余时间: ${l.default().numberShiftTime(Math.floor((864e5 - (currentTime - storedTime)) / 1e3))}`;

      // 如果存储时间有效且超时，重置相关数据
      if (storedTime != null && storedTime !== "" && isPowerModelValid && isTimeExceeded) {
        $zqcc_OverallSystem.sers().userSrv.setPower(u.default.MAX_POWER);
        p.default.unlockCnt = 0;
        $zqcc_OverallSystem.sers().localStorageSrv.set(p.default.infinityPowerModel, 0);
        $zqcc_OverallSystem.sers().localStorageSrv.set(p.default.infinityPowerDate, currentTime);
        window.LookCnt = 0;
        this.updateVideoCnt();
        return;
      }
    }

    // 如果无限力量模型为0，更新为正常状态
    this.tilitubiaoNode.children[1].active = true;
    this.tilitubiaoNode.children[2].active = true;
    this.tilitubiaoNode.children[3].active = false;

    if ($zqcc_OverallSystem.sers().userSrv.isPowerLess()) {
      this.lbRePowerCnt.node.active = true;
      const rePowerTimer = $zqcc_OverallSystem.sers().userSrv.getRePowerTimer();
      const formattedTime = `${Math.trunc(rePowerTimer / 60)}:${Math.trunc(rePowerTimer % 60)}`; // 格式化时间
      this.lbRePowerCnt.string = formattedTime;
      this.number.string = `(${$zqcc_OverallSystem.sers().userSrv.power}/${u.default.MAX_POWER})`;
    } else {
      this.lbRePowerCnt.string = "体力已满";
      this.number.string = `(${$zqcc_OverallSystem.sers().userSrv.power}/${u.default.MAX_POWER})`;
    }
  };
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "lbRePowerCnt", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "number", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "changwanBtn", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "tips", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "tips2", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "wuxiandaojishi", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "tilitubiaoNode", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(h.default);
exports.default = def_getPowerPage;